#include "human.h"
#include <string>


human::human(human&& other)noexcept
{
	m_name = std::move(other.m_name);
	m_alive = other.m_alive;
	m_father = other.m_father;
	m_mother = other.m_mother;
	m_children = std::move(other.m_children);

	other.m_name = {};
	other.m_father = other.m_mother = {};
	//m_children
}

std::shared_ptr<human> human::child(std::string name, std::shared_ptr<human>& pmother, std::shared_ptr<human>& pfather)
{
	std::shared_ptr<human> child(new human(name));
	child->m_father = pfather;
	child->m_mother = pmother;
	pfather->m_children.push_back(child);
	pmother->m_children.push_back(child);
	return child;
}

void human::print_parents(void)
{
	
	if (m_father)
	{
		std::cout << "Father: " << m_father->m_name << "\n";
		std::cout << "Hi's parents: \n";
		m_father->print_parents();
	} else std::cout << "Father: N/A\n";

	if (m_mother)
	{
		std::cout << "Mother: " << m_mother->m_name << "\n";
		std::cout << "Her parents: \n";
		m_mother->print_parents();
	}else std::cout << "Mother: N/A\n";

}

void human::print_children(void)
{
	if (!m_children.empty())
	{		
		for (const auto& x : m_children)
		{
			std::shared_ptr<human> tmp = x.lock();
			std::cout << "\n" << tmp->m_name << "\, ";

			if (tmp->m_children.size()) { std::cout << " has " << tmp->m_children.size() << " children: "; }
			std::cout << "("; 
			tmp->print_children();
			std::cout << ") ";
		}
	}
	else std::cout << "has no children";

}

void human::print_three(void)
{
	std::cout << "My name is " << m_name << "\n\n";
	std::cout << "My parents are: \n\n";
	this->print_parents();
	
	if (m_children.empty())
	{
		std::cout << "\nI have no children" /*<< "\n"*/;
	}
	else
	{
		std::cout << "\nI have " << m_children.size() << " children: " << "\n";
		this->print_children();
	}
}